package com.music.checkpoints.api;

import com.music.checkpoints.common.service.MonitorManager;
import com.music.checkpoints.common.utils.ResultVOUtil;
import com.music.checkpoints.common.vo.ResultVO;
import com.music.checkpoints.common.vo.ScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/monitor")
public class MonitorController {
    @Autowired
    private MonitorManager monitorManager;

    @PostMapping("/login")
    public ResultVO login(@RequestParam("id_card") @NotEmpty(message = "id_card can not be null") String idCard) {
        return ResultVOUtil.success(monitorManager.login(idCard));
    }

    @GetMapping("/examinees")
    public ResultVO examinees(@RequestParam("site_id") @NotEmpty(message = "site_id can not be null") Integer siteId,
                              @RequestParam(value = "page_num", defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) {
        return ResultVOUtil.success(monitorManager.questions(siteId, pageSize, pageNum));
    }

    @PostMapping("/submit/score")
    public ResultVO submitScore(@RequestBody ScoreVO scoreVO) {
        monitorManager.completeScore(scoreVO);
        return ResultVOUtil.success();
    }

    @PostMapping("/missing")
    public ResultVO missingExam(@RequestParam("exam_code") @NotEmpty(message = "exam_code can not be null") String examCode) {
        monitorManager.missingExam(examCode);
        return ResultVOUtil.success();
    }

    @PostMapping("/missing/cancel")
    public ResultVO cancelMissing(@RequestParam("exam_code") @NotEmpty(message = "exam_code can not be null") String examCode) {
        monitorManager.missingCancel(examCode);
        return ResultVOUtil.success();
    }
}
